<script setup>
import HelloWorld from './components/HelloWorld.vue'
import Demo from "./components/Demo.vue";
import {useRoute, useRouter} from "vue-router";
import {ref, watch} from "vue";

const router = useRouter() // 路由跳转
const route = useRoute() // 当前路由，可以获取值
let id = ref(route.query.id)
const goOn=()=>{
  // 跳转路由
  router.push({name :"demo",query:{id:123456}})
}
const goHello =()=>{
  router.push({name:'hello'})
}
// 监听特定 query 参数的变化
watch(
    () => route.query.id,
    (newId, oldId) => {
      id=newId
      console.log('ID 参数变化:', newId)
      // 处理特定参数变化的逻辑
    }
)
</script>

<template>
  <div>
    <a href="https://vite.dev" target="_blank">
      <img src="/vite.svg" class="logo" alt="Vite logo" />
    </a>
    <a href="https://vuejs.org/" target="_blank">
      <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
    </a>
    <button @click="goOn()">跳转路由</button>
    <button @click="goHello()">跳转Hello</button>
    路由id:{{id}}

  </div>
<!--  <Demo/>-->
<!--  <HelloWorld msg="Vite + Vue" />-->
<!--  展示区-->
  <router-view/>
</template>

<style scoped>
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
